package com.shycloud.mido.common.util;

/**
 * @author Xiaoxing Yu
 * @date 2020/11/20 下午2:13
 **/
public class StringUtil {

	private static final char UNDERLINE='_';

	/**
	 * 下划线 转 驼峰
	 * @param param
	 * @return
	 */
	public static String underlineToCamel(String param){
		if (param==null||"".equals(param.trim())){
			return "";
		}
		int len=param.length();
		StringBuilder sb=new StringBuilder(len);
		for (int i = 0; i < len; i++) {
			char c = Character.toLowerCase(param.charAt(i));
			if (c == UNDERLINE){
				if (++i<len){
					sb.append(Character.toUpperCase(param.charAt(i)));
				}
			}else{
				sb.append(c);
			}
		}
		return sb.toString();
	}

	/**
	 * 驼峰命名转为下划线命名
	 * @param para
	 * @return
	 */
	public static String camelToUnderline(String para) {
		StringBuilder sb = new StringBuilder(para);
		int temp = 0;//定位
		if (!para.contains("_")) {
			for (int i = 0; i < para.length(); i++) {
				if (Character.isUpperCase(para.charAt(i))) {
					sb.insert(i + temp, "_");
					temp += 1;
				}
			}
		}
		return sb.toString().toUpperCase();
	}

}
